package com.example.springboottest.service.impl;

import com.example.springboottest.pojo.Permissions;
import com.example.springboottest.pojo.Role;
import com.example.springboottest.pojo.User;
import com.example.springboottest.service.LoginService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {
    @Override
    public User getUserByName(String getMapByName) {

        return getMapByName(getMapByName);
    }



    private User getMapByName(String userName){
        //定义两个权限
        Permissions  permissions1 = new Permissions(1, "query");
        Permissions  permissions2 = new Permissions(2, "add");

        List<Permissions> permissionsList = new ArrayList<>();
        permissionsList.add(permissions1);
        permissionsList.add(permissions2);

        //定义用户实体权限
        Role role = new Role(1, "admin", permissionsList);
        List<Role> roleList = new ArrayList<>();
        roleList.add(role);

        User user = new User(1, "aaa", "123456", roleList);
        Map<String,User> map = new HashMap<>();
        map.put(user.getUsername(),user);

        List<Permissions> permissionsList1 = new ArrayList<>();
        permissionsList1.add(permissions1);

        Role role1 = new Role(2, "user", permissionsList1);
        List<Role> roleList1 = new ArrayList<>();
        roleList1.add(role1);

        User user1 = new User(2, "bbb", "123456", roleList1);
        map.put(user1.getUsername(),user1);

        return map.get(userName);
    }
}
